package com.guanji.learn.service;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.guanji.learn.DTO.UserDTO;
import com.guanji.learn.util.PasswordXlsxUtil;
import org.apache.commons.compress.utils.Lists;
import org.apache.poi.poifs.crypt.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

public class ExcelExportPasswordService {

    public static void main(String[] args) throws Exception {
        List<UserDTO> users = Arrays.asList(
                new UserDTO("张三", 25),
                new UserDTO("李四", 30));

        byte[] encrypted = PasswordXlsxUtil.exportPasswordXlsx(users, "123456");

        /* 可选：落盘验证 */
        Files.write(Paths.get("E:\\protected.xlsx"), encrypted);

        System.out.println("加密 .xlsx 完成，共 " + encrypted.length + " 字节");
    }
}
